package com.lagou.test;


import com.lagou.dao.DeptDao;
import com.lagou.domain.Tbdept;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Mytest {

    @Test
    public void findAll() throws IOException {
        //加载核心配置文件
        InputStream in =  Resources.getResourceAsStream("sqlMapConfig.xml");
        //获得工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in);
        //获取会话对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //获取代理对象
        DeptDao dao = sqlSession.getMapper(DeptDao.class);
        List<Tbdept> list = dao.findAll();
        for(Tbdept dept:list){
            System.out.println(dept);
        }
    }
}
